<template>
	<view>
		<view class="qrcode">
			{{qrcode}}
		</view>
		<view class="copy">
			<text style="color: green" id="btn" :data-clipboard-text="qrcode" @click="copy">复制</text>
		</view>
		<view class="img">
			<image :src="imgSrc" width="100%" style="height: 430px;">
		</view>
		<view style="text-align: center;">
			<canvas class="canvas" canvas-id="qrcode" style=""></canvas>
			<button class="button" type="default" size="mini" @click ="share" style="background-color: #F0AD4E;">保存图片</button>
		</view>
	</view>
</template>
<script>
	import uQRCode from '@/components/uqrcode.js'
	import{
		INVITE_USER
	}from '@/store/mutation-types.js'

	export default{
		data() {
			return {
				imgSrc:'../../../static/icon/default/share.jpg',
				qrcode: "http://121.40.119.212:8085/wishing_front/view/share/register.html",
				downloadImg: "../../../static/icon/default/share.jpg",
				qrcodeSize: 60,
				qrcodeSrc: '',
			}
		},

		onLoad() {
			this.make()
		},
		methods:{
			make(){
				console.log('make函数被调用了')
				uni.showLoading({
					mask:true
				})
				uQRCode.make({
					canvasId: 'qrcode',
					text: this.qrcode,
					size: this.qrcodeSize,
					margin:0,
					success: res => {
						this.qrcodeSrc = res
						this.create()
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			},
			create(){
				uni.showLoading({
					title:'海报生成中',
					mask:true
				})
			},
			copy(){
				let app = this
				uni.setClipboardData({
					data:app.qrcode,
					success() {
						console.log('复制成功')
					}
				})
			},
			share(){
				let app = this
				// app.$toast('图片已保存至相册')
				uni.saveImageToPhotosAlbum({
					// filePath:'../../../static/icon/default/qr.png',
					filePath:this.qrcodeSrc,
					success() {
						app.$toast('保存成功，请在相册中查看')
					}
				})
			},
		}
	}
</script>
<style>
	.canvas {
		margin-top: 715rpx;
		margin-left: 310rpx;
		text-align: center;
		justify-content: center;
		width: 60px;
		height: 60px;
		position: absolute;

	}

	.qrcode{
		word-break: break-all;
		text-align: center;
		background-color: #F4F4F4;
		text-overflow: ellipsis;
	}

	.copy{
		text-align: center;
		margin-top: 5px;
	}

	.img{
		float: left;
		margin-top: 10rpx;
		z-index: 999;
	}

	.share{
		margin-top: 20px; text-align: center;
	}
	.button{
		text-align: center;
		background-color: #F0AD4E;
		width:auto;
		height: auto;
	    font-size: 8;
		color: #F0F0F0;
		border-radius: 15px;
		margin-bottom: 20px;
	}
</style>




